<template>
  <div class="container-md mx-auto">
    <section class="py-5 text-center container">
      <div class="row py-lg-5">
        <div class="col-lg-6 col-md-8 mx-auto">
          <img src="../assets/callout.svg" alt="callout" class="w-50" />
          <h2 class="font-weight-light">随心写作，自由表达</h2>
          <p>
            <router-link to="/posts/create" class="btn btn-primary my-2">
              开始写文章
            </router-link>
          </p>
        </div>
      </div>
    </section>
    <h4 class="font-weight-bold text-center mb-4">发现精彩</h4>
    <column-list :list="list"></column-list>
    <button
      v-if="!isLastPage"
      class="btn btn-outline-primary mt-2 mb-5 mx-auto d-block w-25"
      @click.prevent="loadMoreData"
    >
      加载更多
    </button>
  </div>
</template>
<script lang="ts">
import { defineComponent, computed, onMounted, reactive } from 'vue'
import { useStore } from 'vuex'
import ColumnList from '@/components/ColumnList.vue'
import { IStore } from '@/types/index'
import useLoadMore from '@/hooks/useLoadMore'
export default defineComponent({
  name: 'Home',
  components: {
    ColumnList
  },
  setup() {
    const store = useStore<IStore>()
    const list = computed(() => store.state.columnList)
    const state = reactive({
      pageSize: 3,
      currentPage: 1
    })
    const { loadMoreData, isLastPage } = useLoadMore('getColumns', state)
    onMounted(() => {
      loadMoreData()
    })
    return {
      list,
      isLastPage,
      loadMoreData
    }
  }
})
</script>
